package com.muyu.vehicle.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vehicle.common.log.annotation.Log;
import com.vehicle.common.log.enums.BusinessType;
import com.vehicle.common.security.annotation.PreAuthorize;
import com.muyu.vehicle.domain.VehicleFaultInfo;
import com.muyu.vehicle.service.IVehicleFaultInfoService;
import com.vehicle.common.core.web.controller.BaseController;
import com.vehicle.common.core.web.domain.AjaxResult;
import com.vehicle.common.core.utils.poi.ExcelUtil;
import com.vehicle.common.core.web.page.TableDataInfo;

/**
 * 车辆故障码Controller
 *
 * @author muyu
 * @date 2021-09-04
 */
@RestController
@RequestMapping("/fault")
public class VehicleFaultInfoController extends BaseController
{
    @Autowired
    private IVehicleFaultInfoService vehicleFaultInfoService;

    /**
     * 查询车辆故障码列表
     */
    @PreAuthorize(hasPermi = "vehicle:fault:list")
    @GetMapping("/list")
    public TableDataInfo list(VehicleFaultInfo vehicleFaultInfo)
    {
        startPage();
        List<VehicleFaultInfo> list = vehicleFaultInfoService.selectVehicleFaultInfoList(vehicleFaultInfo);
        return getDataTable(list);
    }

    /**
     * 导出车辆故障码列表
     */
    @PreAuthorize(hasPermi = "vehicle:fault:export")
    @Log(title = "车辆故障码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VehicleFaultInfo vehicleFaultInfo) throws IOException
    {
        List<VehicleFaultInfo> list = vehicleFaultInfoService.selectVehicleFaultInfoList(vehicleFaultInfo);
        ExcelUtil<VehicleFaultInfo> util = new ExcelUtil<VehicleFaultInfo>(VehicleFaultInfo.class);
        util.exportExcel(response, list, "车辆故障码数据");
    }

    /**
     * 获取车辆故障码详细信息
     */
    @PreAuthorize(hasPermi = "vehicle:fault:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(vehicleFaultInfoService.selectVehicleFaultInfoById(id));
    }

    /**
     * 新增车辆故障码
     */
    @PreAuthorize(hasPermi = "vehicle:fault:add")
    @Log(title = "车辆故障码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VehicleFaultInfo vehicleFaultInfo)
    {
        return toAjax(vehicleFaultInfoService.insertVehicleFaultInfo(vehicleFaultInfo));
    }

    /**
     * 修改车辆故障码
     */
    @PreAuthorize(hasPermi = "vehicle:fault:edit")
    @Log(title = "车辆故障码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VehicleFaultInfo vehicleFaultInfo)
    {
        return toAjax(vehicleFaultInfoService.updateVehicleFaultInfo(vehicleFaultInfo));
    }

    /**
     * 删除车辆故障码
     */
    @PreAuthorize(hasPermi = "vehicle:fault:remove")
    @Log(title = "车辆故障码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(vehicleFaultInfoService.deleteVehicleFaultInfoByIds(ids));
    }
}
